<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>扫码进入小程序</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
  <style>
    body { background: #f7f7f7; margin: 0; padding: 0; font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif; color: #222; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }
    .container { background: #fff; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); padding: 32px 24px 24px 24px; max-width: 350px; width: 90vw; text-align: center; }
    .qrcode-img { width: 220px; height: 220px; margin: 0 auto 18px auto; background: #f2f2f2; border-radius: 8px; object-fit: contain; box-shadow: 0 1px 6px rgba(0,0,0,0.06); }
    .title { font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; }
    .desc { color: #666; font-size: 1rem; margin-bottom: 18px; }
    .tip { color: #ff9800; font-size: 0.98rem; margin-top: 10px; }
  </style>
</head>
<body>
  <div class="container">
    <div class="title" id="mp-title">小程序码</div>
    <img class="qrcode-img" id="qrcode-img" src="" alt="二维码">
    <div class="desc" id="mp-desc">请长按识别二维码，进入小程序</div>
    <div class="tip">如无法识别，请截图保存后用微信扫码</div>
  </div>
  <script>
    // 获取URL参数
    function getQueryParam(name) {
      const url = window.location.search;
      const params = new URLSearchParams(url);
      return params.get(name);
    }
    const id = getQueryParam('id');
    const sign = getQueryParam('sign');
    if (!id || !sign) {
      document.getElementById('mp-title').innerText = '参数缺失';
      document.getElementById('mp-desc').innerText = '请联系管理员';
    } else {
      // 修改JavaScript中的fetch调用
      fetch(`/api/anon/miniapp-landing?id=${encodeURIComponent(id)}&sign=${encodeURIComponent(sign)}`)
        .then(res => res.json())
        .then(response => {
          // 修改这里：检查 code === 200 而不是 success
          if(response.code === 200 && response.data && response.data.miniAppName && response.data.miniAppCodeImg) {
            document.getElementById('mp-title').innerText = response.data.miniAppName;
            document.getElementById('qrcode-img').src = response.data.miniAppCodeImg;
          } else {
            document.getElementById('mp-title').innerText = '二维码信息有误';
            document.getElementById('mp-desc').innerText = '请联系管理员';
            console.error('API响应错误:', response);
          }
        })
        .catch(error => {
          document.getElementById('mp-title').innerText = '二维码信息获取失败';
          document.getElementById('mp-desc').innerText = '请联系管理员';
          console.error('请求失败:', error);
        });
    }
  </script>
</body>
</html>